import {
  NativeModules,
  NativeEventEmitter,
} from 'react-native';
import { useEffect } from 'react';

type RNCRecordWaveViewType = {
  start: () => void;
  // android
  // stop: (callback: (res: string | number) => void) => void
  // ios
  // stop: () => Promise<string>
};


const RecordAudioManager = NativeModules.RecordAudioManager

const recordAudioManagerEmitter = new NativeEventEmitter(RecordAudioManager)

export function useAudioUpdateMeters<T>(handler: (data: T) => void) {
  useEffect(() => {
    const subscription = recordAudioManagerEmitter.addListener(
      'onRecorderAudioUpdateMeters',
      (data) => handler(data.value)
    );
    return () => {
      subscription.remove()
    }
  }, [handler])
}

export default RecordAudioManager
